package com.woniuxy.company5.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.company5.dto.LRepProgressDto;
import com.woniuxy.company5.entity.RepProgress;
import com.woniuxy.company5.service.RepProgressService;
import com.woniuxy.company5.util.Result;
import com.woniuxy.company5.vo.LRepDistributionVo;
import com.woniuxy.company5.vo.LRepProgressVo;
import com.woniuxy.company5.vo.RepDistributionVo;
import com.woniuxy.company5.vo.RepProgressVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/repProgress")
public class RepProgressController {
    @Resource
    private RepProgressService repProgressService;
    @PostMapping("")
    public Result add(@RequestBody LRepDistributionVo repDistributionVo){
        repProgressService.insertSelective(repDistributionVo);
        return Result.ok();
    }
    @PostMapping("query")
    public Result queryByLike(@RequestBody LRepProgressDto repProgressDto){
        PageHelper.startPage(repProgressDto.getCurrentPage(),repProgressDto.getPageSize(),true);
        List<LRepProgressVo> UserCustomer = repProgressService.selectByLike(repProgressDto);
        PageInfo<LRepProgressVo> pageInfo = new PageInfo<>(UserCustomer);
        return Result.ok().data("userList",UserCustomer).data("total",pageInfo.getTotal());
    }
    @GetMapping("{id}")
    public Result queryById(@PathVariable("id") Long id){
        RepProgress repProgress = repProgressService.selectByPrimaryKey(id);
        return Result.ok().data("user",repProgress);
    }
    @PutMapping("")
    public Result update(@RequestBody RepProgress repProgress){
        repProgressService.updateByPrimaryKeySelective(repProgress);
        return Result.ok();
    }
}
